package org.serverct.finalfight.game.hadesgame.events;

import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.serverct.finalfight.game.hadesgame.EventType;
import org.serverct.finalfight.internal.game.basic.BasicGame;
import org.serverct.finalfight.internal.game.hadesgame.ContinuousEvent;

import java.util.UUID;

public class TantrummingMoon extends ContinuousEvent {

    public TantrummingMoon(BasicGame game, EventType type) {
        super(game, type);
    }

    @Override
    public void tick() {
        for (UUID uuid : this.game.players.keySet()) {
            Player player = Bukkit.getPlayer(uuid);
            if (!this.game.isAlive(player)) {
                return;
            }
            Location loc = player.getLocation();
            World world = player.getWorld();
            if (world.getTime() <= 0 || world.getTime() >= 15000) {
                if (loc.getY() >= world.getHighestBlockYAt(loc)) {
                    player.removePotionEffect(PotionEffectType.LEVITATION);
                    player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 60, 0));
                }
            }
        }
    }
}
